<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <style>
    </style>
</head>
<style>
    .home:before {
        content: url(../image/home.png);
    }

    .refresh:before {
        content: url(../image/refresh.png);
    }

    .company:before {
        content: url(../image/company.png);
    }

    .pa-title {
        font-size: 17px;
        color: black;
        font-weight: bold;
    }

    .pa-title-content {
        font-size: 17px;
        color: black;
    }

    body {
        background-color: #D9D8DB;
    }

    .pa_scbg_left_top {
        background-color: #D9D8DB;
        border-radius: 5px;
        height: 80px;
        color: white;
    }

    .pa_scbg_left_bottom {
        background-color: #254060;
        height: 350px;
        border-radius: 5px;
        color: white;
        margin-top: 10px;
        overflow: auto;
    }


    .pa_scbg_right {
        background-color: #254060;
        height: 440px;
        border-radius: 5px;
        color: white;
        margin-left: 10px;
    }

    .pa_scbg_but {
        height: 50px;
        line-height: 50px;
        margin-top: 15px;
        margin-left: 12px;
        float: left;
        width: 100px;
        font-size: 18px;
        color: white;
        text-align: center;
    }

    .pa_scbg_but2 {
        height: 50px;
        line-height: 50px;
        margin-top: 15px;
        margin-left: 12px;
        float: left;
        width: 150px;
        font-size: 18px;
        color: white;
        text-align: center;
    }

    .pa_scbg_content {
        font-size: 15px;
        color: white;
        margin-top: 5px;
    }

    p {
        font-size: 17px;
        color: black;
        font-weight: bold;
        text-align: center;
    }

    table {
        width: 100%;
        table-layout: fixed;
        word-wrap: break-word;
    }

    td {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }

    .startBut {
        font-size: 17px;
        color: white;
        font-weight: bold;
        float: right;
        width: 60px;
        margin-right: 10px;
        height: 25px;
        line-height: 25px;
        margin-top: 2.5px;
        text-align: center;
        background-color: green;
    }

    .marquee {
        white-space: nowrap;
        animation: marquee 5s linear infinite;
    }

    @keyframes marquee {
        0% {
            transform: translateX(100%);
        }

        100% {
            transform: translateX(-200%);
        }
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #D9D8DB">
        <div style="width: 10%;height: 60px;float: left;padding-top: 6px;">
            <a class="aui-pull-left aui-btn ">
                <span class="aui-iconfont company"></span>
            </a>
        </div>
        <div style="width: 10%;height: 60px;float: left;">
            <div style="text-align: left;">
                <span class="pa-title">富晟久泰</span>
            </div>
        </div>
        <div style="width: 70%;height: 60px;float: left;">
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="locationName"></span>
            </div>
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCenterName"></span>
            </div>
            <div style="width:24%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCellName"></span>
            </div>
            <div style="width:40%; float: left; text-align: left;">
                <span class="pa-title-content" id="nowDate"></span>
            </div>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn " onclick="refresh()">
                <span class="aui-iconfont refresh"></span>
            </a>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn" onclick="closeWin()">
                <span class="aui-iconfont home"></span>
            </a>
        </div>
    </header>
    <div class="aui-content">
        <div class="aui-flex-col aui-flex-center" style="height: 30px;">
            <div class="aui-flex-item-12">
                <p>报工</p>
            </div>
        </div>

        <div class="aui-flex-col aui-flex-center" style="margin-left: 1%;margin-right: 1%;">
            <div class="aui-flex-item-12">
                <div class="aui-flex-col pa_scbg_left_top">
                    <div class="pa_scbg_but2" style="background-color: #00BFBF;" onclick="openReport()">合格品报工</div>
                    <div class="pa_scbg_but2" style="background-color: #D9001B;" onclick="openUnReport()">不合格品报工</div>
                    <div class="pa_scbg_but" style="background-color: #528302;" onclick="beforeComplete()">完工</div>
                    <div class="pa_scbg_but" style="background-color: #00BFBF;" onclick="back()">撤销</div> 
                    <!-- <div class="pa_scbg_but" style="background-color: #D9001B;" onclick="scrap()">报废</div> --> 
                    <div class="pa_scbg_but" style="background-color: #D9001B;" onclick="cancle()">关闭</div>

                </div>

                <div class="aui-flex-col pa_scbg_left_bottom">
                    <div class="aui-flex-item-12">
                        <div class="aui-flex-col " style="height: 50px; margin-top: 15px;">
                            <div style="font-size: 20px;color: white;font-weight: bold;width: 15%;">工单信息
                            </div>
                            <div style="background-color: white;width: 20%;height: 30px;margin-left: 5px ;">
                                <input type="text" style="font-size: 14px;margin-top: -15px;" placeholder="请输入物料编码"
                                    id="mrlCode" />
                            </div>
                            <div style="background-color: white;width: 20%;height: 30px;margin-left: 5px ;">
                                <input type="text" style="font-size: 14px;margin-top: -15px;" placeholder="请输入规格"
                                    id="drawing" />
                            </div>
                            <div style="background-color: white;width: 20%;height: 30px;margin-left: 5px ;margin-right: 5px ;"
                                onclick="timePicker('prodDate');">
                                <input type="text" style="font-size: 14px;margin-top: -15px;" placeholder="选择日期"
                                    class="aui-input" id="prodDate">
                            </div>
                            <div class="startBut" onclick="doSearch()">查询</div>
                        </div>
                        <div class="aui-flex-col ">
                            <div style="height: 100%;width: 100%;">
                                <table class="table" border="1px solid gray" cellspacing="0" cellpadding="0">
                                    <thead>
                                        <tr style="text-align: center;color: white;font-size: 18px;height: 40px;">
                                            <td algin='center' style="width:4%;"></td>
                                            <td algin='center' style="width:18%">工单号</td>
                                            <td algin='center' style="width:13%">物料编码</td>
                                            <td algin='center' style="width:18%">规格</td>
                                            <td algin='center' style="width:13%">物料名称</td>
                                            <td algin='center' style="width:8%">计划数</td>
                                            <td algin='center' style="width:8%">上挂数</td>
                                            <td algin='center' style="width:8%">下挂数</td>
                                            <td algin='center' style="width:8%">合格数</td>
                                            <td algin='center' style="width:11%">不合格数</td>
                                            <td algin='center' style="width:9%">报工数</td>
                                            <td style="display: none;">追溯类型</td>
                                            <td style="display: none;">sysid</td>
                                        </tr>
                                    </thead>
                                    <tbody id="reportDataHtml">
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>


        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";

    //初始化
    apiready = function () {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        //产线工位信息
        document.getElementById("locationName").innerHTML = api.pageParam.locationName;
        document.getElementById("workCenterName").innerHTML = api.pageParam.workCenterName;
        document.getElementById("workCellName").innerHTML = api.pageParam.workCellName;
        document.getElementById("nowDate").innerHTML = getTimeCommon();
        //当前时间刷新
        window.setInterval("getTime()", 1000);
        //1:初始化当前日期
        crateDate();

        doSearch();



    }
    //时间选择器
    function timePicker(id) {
        api.openPicker({
            type: 'date',
            date: new Date(),
            title: '选择日期'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#" + id).val(date);

                //查询表格数据
                doSearch();
            }
        });
    }
    //获取当前日期
    function crateDate() {
        if (api.pageParam.proddate == null || api.pageParam.proddate == "" || api.pageParam.proddate == undefined) {
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
            var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
            $("#prodDate").val(year + "-" + month + "-" + day);
        } else {
            $("#prodDate").val(api.pageParam.proddate);
        }
    }
    //时间刷新
    function getTime() {
        document.getElementById("nowDate").innerHTML = getTimeCommon();
    }
    //查询工单信息
    function doSearch() {
        var proddate = $("#prodDate").val();
        var mrlCode = $("#mrlCode").val();//物料编码
        var drawing = $("#drawing").val();//规格
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyDDWorkOrder";
        var data = {
            values: {
                mrlCode: mrlCode,
                drawing: drawing,
                proddate: proddate,
                workCenterCode: api.pageParam.workCenterCode,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 0) {
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {

                        if(list[i].planQty != (list[i].bgQty + list[i].unBgQty)){

                            html += "<tr style='text-align: center;color: white;font-size: 14px;height:50px;'>";
                            html += "<td><input name='sub' type='checkbox' /></td>"
                            // html += "<td name='index'>" + (i + 1) + "</td>";
                            html += "<td><div class='marquee' name='workOrderCode' id='workOrderCode'>" + list[i].workOrderCode + "</div></td>";
                            html += "<td name='mrlCode'>" + list[i].mrlCode + "</td>";
                            html += "<td ><div class='marquee' name='drawing' id='drawing'>" + list[i].drawing + "</div></td>";
                            html += "<td ><div class='marquee' name='mrlName' id='mrlName'>" + list[i].mrlName + "</div></td>";
                            html += "<td name='planQty'>" + list[i].planQty + "</td>";
                            html += "<td name='hangUpQty'>" + list[i].hangUpQty + "</td>";
                            html += "<td name='hangDownQty'>" + list[i].hangDownQty + "</td>";
                            html += "<td name='qualifyQty'>" + list[i].qualifyQty + "</td>";
                            html += "<td name='unQualifyQty'>" + list[i].unQualifyQty + "</td>";
                            html += "<td name='bgQty'>" + (list[i].bgQty + list[i].unBgQty) + "</td>";
                            html += "<td name='retrospectFlag'>" + list[i].retrospectFlag + "</td>";
                            html += "</tr>";
                        }
                    }
                    $api.html($api.byId("reportDataHtml"), html);

                    var tdElements = document.querySelectorAll('td div');
                    // 遍历div元素
                    for (var i = 0; i < tdElements.length; i++) {
                        // 获取当前ddiv元素的宽度
                        var tdWidth = tdElements[i].offsetWidth;

                        // 获取当前div元素中输入的内容长度
                        var contentLength = tdElements[i].scrollWidth;

                        // 判断内容长度是否大于div的宽度
                        if (contentLength > tdWidth) {

                        } else {
                            //移除跑马灯效果
                            tdElements[i].classList.remove("marquee");
                        }
                    }
                } else {
                    $api.html($api.byId("reportDataHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }


    //合格品报工
    function openReport() {
        var workOrderCode = "";
        var retrospectFlag = "";
        var count = 0;
        //选中数据
        var check = $("input[name='sub']:checked");
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            workOrderCode = row.find("[name='workOrderCode']").html();
            retrospectFlag = row.find("[name='retrospectFlag']").html();
            count++;
        });
        if (count != 1) {
            api.toast({
                msg: "请选择一条工单信息数据!",
                duration: 3000
            });
            return;
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/checkBom";
        var data = {
            values: {
                workOrderCode: workOrderCode,
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';
        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 0) {
                    if (workOrderCode != "") {
                        var pageParam = api.pageParam;
                        pageParam.workOrderCode = workOrderCode;
                        pageParam.retrospectFlag = retrospectFlag;
                        //批次追溯
                        if (pageParam.retrospectFlag == "0") {
                            api.openWin({
                                name: "productionAssemblyScbgDd_OK",
                                url: 'productionAssemblyScbgDd_OK.html',
                                pageParam: pageParam,
                            });


                        }
                    }

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });


    }

    //不合格品报工
    function openUnReport() {
        var workOrderCode = "";
        var retrospectFlag = "";
        var count = 0;
        //选中数据
        var check = $("input[name='sub']:checked");
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            workOrderCode = row.find("[name='workOrderCode']").html();
            retrospectFlag = row.find("[name='retrospectFlag']").html();
            count++;
        });
        if (count != 1) {
            api.toast({
                msg: "请选择一条工单信息数据!",
                duration: 3000
            });
            return;
        }

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/checkBom";
        var data = {
            values: {
                workOrderCode: workOrderCode,
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';
        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 0) {
                    var pageParam = api.pageParam;
                    pageParam.workOrderCode = workOrderCode;
                    pageParam.retrospectFlag = retrospectFlag;
                    //批次追溯
                    if (pageParam.retrospectFlag == "0") {

                        api.openWin({
                            name: "productionAssemblyScbgDd_NG",
                            url: 'productionAssemblyScbgDd_NG.html',
                            pageParam: pageParam,
                        });

                        //单件追溯
                    } else {
                        api.openWin({
                            name: "productionAssemblyScbgUnique_NG",
                            url: 'productionAssemblyScbgUnique_NG.html',
                            pageParam: pageParam,
                        });


                    }
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });


    }

    //撤销
    function back() {
        var workOrderCode = "";
        var count = 0;
        //选中数据
        var check = $("input[name='sub']:checked");
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            workOrderCode = row.find("[name='workOrderCode']").html();
            count++;
        });
        if (count != 1) {
            api.toast({
                msg: "请选择一条工单信息数据!",
                duration: 3000
            });
            return;
        }

        var pageParam = api.pageParam;
        pageParam.workOrderCode = workOrderCode;
        api.openWin({
            name: "productionAssemblyScbgDd_back",
            url: 'productionAssemblyScbgDd_back.html',
            pageParam: pageParam,
        });
    }

    function beforeComplete() {
        api.confirm({
            title: '提示',
            msg: '完工后工单无法继续报工，是否确认完工',
            buttons: ['确定', '取消']
        }, function (ret, err) {
            if (ret.buttonIndex == 1) {
                complete()
            }
        });
    }

    //完工
    function complete() {
        var workOrderCode = "";
        var count = 0;
        //选中数据
        var check = $("input[name='sub']:checked");
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            workOrderCode = row.find("[name='workOrderCode']").html();
            count++;
        });
        if (count != 1) {
            api.toast({
                msg: "请选择一条工单信息数据!",
                duration: 3000
            });
            return;
        }
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyUpdateWorkOrder";
        var data = {
            values: {
                workOrderCodeStr: workOrderCode,
                workCenterCode: api.pageParam.workCenterCode,
                workCellCode: api.pageParam.workCellCode,
                state: "完工",
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功",
                        duration: 3000
                    });

                    cancle();

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });

    }

    //刷新按钮
    function refresh() {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        doSearch();

    }

    //返回上级页面
    function cancle() {
        api.closeWin({});
        api.execScript({
            name: api.pageParam.name,
            script: 'refresh()'
        });
    }

    //零件报废
    function scrap() {
        var workOrderCode = "";
        var count = 0;
        //选中数据
        var check = $("input[name='sub']:checked");
        var mrlCode = "";
        var mrlName = "";
        var drawing = "";
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            workOrderCode = row.find("[name='workOrderCode']").html();
            mrlCode = row.find("[name='mrlCode']").html();
            mrlName = row.find("[name='mrlName']").html();
            drawing = row.find("[name='drawing']").html();
            count++;
        });
        if (count != 1) {
            api.toast({
                msg: "请选择一条工单信息数据!",
                duration: 3000
            });
            return;
        }
        var pageParam = api.pageParam;
        pageParam.workOrderCode = workOrderCode;
        pageParam.mrlCode = mrlCode;
        pageParam.mrlName = mrlName;
        pageParam.drawing = drawing;
        pageParam.name = "productionAssemblyScbg";
        var rootName = pageParam.rootName;
        if (rootName == "productionAssemblyInjection") {
            api.openWin({
                name: "productionAssemblyScrap_detail",
                url: 'productionAssemblyScrap_detail.html',
                pageParam: pageParam,
            });
        } else {
            api.openWin({
                name: "productionAssemblyScrap_detail_rqtm",
                url: 'productionAssemblyScrap_detail_rqtm.html',
                pageParam: pageParam,
            });
        }




    }

    //返回按钮
    function closeWin() {
        api.closeToWin({ name: api.pageParam.rootName });
        api.execScript({
            name: api.pageParam.rootName,
            script: 'refresh()'
        });
    }
</script>

</html>